/****************************************************
* Unity版本：2022.1.21f1c1
* Version：0.1
* Company：DefaultCompany
* 日期：2023/07/10 16:46:40
*****************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HHHFramework
{
    public class UnityTimer
    {
        System.Timers.Timer timer;
        Action elapsed;
        public UnityTimer()
        {
            timer = new System.Timers.Timer();
            timer.Interval = 3000;
            timer.Elapsed += FinishTimer;
        }
        public UnityTimer(double time, Action action)
        {
            timer = new System.Timers.Timer();
            //间隔
            timer.Interval = time;
            timer.AutoReset = false;
            ///结束
            timer.Elapsed += FinishTimer;
            elapsed = action;
        }

        public void Start()
        {
            Debug.Log("开始" + System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff"));

            timer.Start();
        }
        public bool isEnded()
        {
            return timer.Enabled;
        }
        public void Stop()
        {
            timer.Stop();
        }

        public void FinishTimer(object sender, System.Timers.ElapsedEventArgs e)
        {
            Debug.Log("timer3:完成计时:" + e.SignalTime.ToString("yyyy-MM-dd hh:mm:ss fff"));
            elapsed?.Invoke();
            timer.Stop();
            timer.Close();
        }

    }

}
